<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入 
* deck.gl (https://github.com/visgl/deck.gl)
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title data-i18n="resources.title_mb_deckglLayer_arcLayer"></title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript" include="widgets" src="../js/include-web.js"></script>
<script type="text/javascript" include="deck" src="../../dist/maplibregl/include-maplibregl.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io",
        url = host + "/iserver/services/map-china/rest/maps/ChinaDark";
    var map, deckglLayer;
    var attribution = "<a href='https://maplibre.org/' target='_blank'>© MapLibre </a>" +
            " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
            " Map Data <span>© <a href='https://uber.github.io/deck.gl' target='_blank'>deck.gl</a></span> ";

    map = new maplibregl.Map({
        container: 'map',
        style: {
            "version": 8,
            "sources": {
                "raster-tiles": {
                    "attribution": attribution,
                    "type": "raster",
                    "tiles": [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
                    "tileSize": 256,
                },
            },
            "layers": [{
                "id": "simple-tiles",
                "type": "raster",
                "source": "raster-tiles",
                "minzoom": 0,
                "maxzoom": 22
            }]
        },
        center: [-122.271604, 37.803664],
        zoom: 10,
    });
    map.addControl(new maplibregl.NavigationControl(), 'top-left');

    widgets.loader.showLoader("data loading...");

    $.get('../data/deck.gl/bart-segments.json', function (features) {
        widgets.loader.removeLoader();
        addLayer(features);
    });

    function addLayer(features) {

        deckglLayer = new maplibregl.supermap.DeckglLayer("arc-layer", {
            data: features,
            props: {
                strokeWidth: 12 //线宽
                //该类型可配置的其他参数有：
                //fp64 否应以高精度64位模式呈现图层，默认为 false
            },
            callback: {
//                getStrokeWidth: 12,
                getSourcePosition: function(d) { return d.from.coordinates },
                getTargetPosition: function(d) { return d.to.coordinates },
                getSourceColor: function(d) { return [Math.sqrt(d.inbound), 140, 0] },
                getTargetColor: function(d) { return [Math.sqrt(d.outbound), 140, 0] },
            }
        });
        map.addLayer(deckglLayer);
    }

    var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
    /*16进制颜色转为RGB格式*/
    String.prototype.colorRgb = function () {
        var sColor = this.toLowerCase();
        if (sColor && reg.test(sColor)) {
            if (sColor.length === 4) {
                var sColorNew = "#";
                for (var i = 1; i < 4; i += 1) {
                    sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
                }
                sColor = sColorNew;
            }
            //处理六位的颜色值
            var sColorChange = [];
            for (var i = 1; i < 7; i += 2) {
                sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
            }
            return sColorChange;
        } else {
            return sColor;
        }
    }

</script>
</body>
</html>
